﻿using OpenCvSharp;
using Prism.Regions;
using SiliconSelect.Common;
using System;
using System.Drawing.Imaging;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using XrayDirection.Common;
using XrayDirection.DAL.LocalDataAccess;
using XrayDirection.Services;
using XrayDirection.ViewModels;

namespace XrayDirection.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainView : System.Windows.Window
    {
        private readonly MainViewModel mainVm;
        private readonly IRegionManager regionManager;

        /// <summary>
        /// 构造函数注入MainViewModel类,在Prism框架实例化MainView的时候,会自动从容器中获取MainViewModel
        /// 的实例对象,然后MainViewModel被我们注册为了单例模式,所以获取的是同一个MainViewModel实例.
        /// </summary>
        /// <param name="mainVm"></param>
        /// <param name="regionManager"></param>
        public MainView(MainViewModel mainVm, IRegionManager regionManager)
        {
            InitializeComponent();
            this.mainVm = mainVm;
            this.regionManager = regionManager;
            WindowState = WindowState.Maximized;
            mainVm.AppMaxminzeState = "最大化";

            // 页面加载的时候,指定默认页面显示
            Loaded += MainView_Loaded;
        }

        private void MainView_Loaded(object sender, RoutedEventArgs e)
        {
            // 默认显示首页
            regionManager.Regions[ConstantManager.MainViewRegion].RequestNavigate(nameof(IndexView));
        }
        private void MouseDouble_OnClick(object sender, MouseButtonEventArgs e)
        {
            if (WindowState == WindowState.Normal)
            {
                WindowState = WindowState.Maximized;
                mainVm.AppMaxminzeState = "还原";
            }
            else
            {
                WindowState = WindowState.Normal;
                mainVm.AppMaxminzeState = "最大化";
            }
        }

        private void MouseLeftButtonDown_OnClick(object sender, MouseButtonEventArgs e)
        {
            DragMove();
        }

        private void BtnMinus_OnClick(object sender, RoutedEventArgs e)
        {
            WindowState = WindowState.Minimized;
        }

        private void BtnMaxmize_OnClick(object sender, RoutedEventArgs e)
        {
            if (WindowState == WindowState.Maximized)
            {
                WindowState = WindowState.Normal;
                mainVm.AppMaxminzeState = "最大化";
            }
            else
            {
                WindowState = WindowState.Maximized;
                mainVm.AppMaxminzeState = "还原";
            }
        }

        private void BtnClose_OnClick(object sender, RoutedEventArgs e)
        {
            Close();
        }

        private void BtnGoBackMouseDouble_OnClick(object sender, MouseButtonEventArgs e)
        {
            // 事件已处理,不会继续往上传递,就是双击时间比,如果放大或者缩小不再起作用.
            e.Handled = true;
        }

        private void MenuToggleButton_OnClick(object sender, RoutedEventArgs e)
        {

        }

        private void Selection_OnChange(object sender, SelectionChangedEventArgs e)
        {
            drawerHost.IsLeftDrawerOpen = false;
        }

        private void BtnGoForwardMouseDouble_OnClick(object sender, MouseButtonEventArgs e)
        {
            // 事件已经处理,不会继续往上传递,就是双击事件比如果放大或者缩小不再起作用.
            e.Handled = true;
        }


        // 
    }
}
